<?php

namespace App\Models\OpenShop\InvestmentPromotion;

use App\Enums\OpenShop\InvestmentPromotion\MainProcessEnum;
use App\Enums\OpenShop\InvestmentPromotion\UploadFileResourceEnum;
use App\Models\BaseModel;
use App\Models\OpenShop\ShopEngineeringConstruction\OpenShopEngineeringConstructionModel;
use App\Models\OpenShop\SiteLocation\OpenShopSiteLocationModel;
use App\Models\Traits\KfSoftDeletes;
use App\Support\ChangeSupport;
use DateTimeInterface;

class OpenShopUploadFileResourceModel extends BaseModel
{
    use KfSoftDeletes;

    protected $fillable = [
        'orderNo',
        'type',
        'url',
        'position',
        'sort',
        'isDeleted',
        'createdAt',
        'createdByUid',
        'updatedAt',
        'updatedByUid',
        'isPublic',
    ];

    const FILE_TYPE_IMG  = 1;
    const FILE_TYPE_CAD  = 2;
    const FILE_TYPE_PDF  = 3;
    const FILE_TYPE_XLSX = 4;
    const FILE_TYPE_PPT  = 5;
    const FILE_TYPE_VIDEO = 7;


    public static array $orderLogTranslate = [
        UploadFileResourceEnum::ENGINEERING_CONSTRUCTION_1        => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_PICTURE,
            "desc" => "头部图片"
        ],
        UploadFileResourceEnum::ENGINEERING_CONSTRUCTION_2        => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_PICTURE,
            "desc" => "店内图片"
        ],
        UploadFileResourceEnum::ENGINEERING_CONSTRUCTION_3        => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_PICTURE,
            "desc" => "店外夜拍"
        ],
        //空间设计
        UploadFileResourceEnum::SPACE_DESIGN_PDF_PLANE            => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_FILE,
            "desc" => "设计图PDF"
        ],
        UploadFileResourceEnum::SPACE_DESIGN_CAD_CONSTRUCTION     => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_FILE,
            "desc" => "效果图CAD"
        ],
        UploadFileResourceEnum::SPACE_DESIGN_PDF_CONSTRUCTION     => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_FILE,
            "desc" => "效果图PDF"
        ],
        UploadFileResourceEnum::SPACE_DESIGN_IMG                  => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_PICTURE,
            "desc" => "效果图"
        ],
        UploadFileResourceEnum::SPACE_DESIGN_CAD_PLANE            => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_FILE,
            "desc" => "设计图CAD"
        ],
        UploadFileResourceEnum::SPACE_DESIGN_SOFT_XLSX            => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_FILE,
            "desc" => "软转报价清单"
        ],
        UploadFileResourceEnum::SELECT_LOCATION_CASH_TYPE_MAPPING => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_PICTURE,
            "desc" => "第三方收银证明"
        ],
        UploadFileResourceEnum::START_BUSINESS_1 => [
            "type" => ChangeSupport::FILED_TYPE_PRIVATE_FILE,
            "desc" => "开业报告文件"
        ],
    ];


    protected $table = 'open_shop_upload_file_resource';

    protected function serializeDate(DateTimeInterface $date)
    {
        return $date->format("Y-m-d H:i:s");
    }

    public function getFormatUrlAttribute(): string
    {
        if ($this->isPublic == 1) {
            return picturePath($this->url);
        }

        return privateFilePath($this->url);
    }

    public function openShopSiteLocationsRel()
    {
        return $this->hasOne(OpenShopSiteLocationModel::class, 'orderNo', 'orderNo');
    }
}
